<?
header("Content-type:text/html; charset=utf-8");
$ac='16ucom';
$pw='c33367701511b4f6020ec61ded352059';
$inSide= new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
include 'aisisen_class.php';
$ass = new AiSiSen($lid);  //艾斯森
$AGENT_KEY = 'a3035f808d04912b8c568dc2c895ed2c';
// $AGENT_KEY = 'b270657fc5677facee5312a194bd9da4';

if (!class_exists("go_sql")){
	include("/var/www/html/new/conf/le.je");
	$le=new go_sql();
	$le->connect();
}
// $txt1 = $_REQUEST['data']; 
$txt1= '%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%0A%3Creq%3E%0A++++%3CinterfaceVersion%3E1.0.0.0%3C%2FinterfaceVersion%3E%0A++++%3CmerchantNo%3EFXS031%3C%2FmerchantNo%3E%0A++++%3CreqSerialNo%3E1%3C%2FreqSerialNo%3E%0A++++%3CreqTime%3E2015-06-05+16%3A45%3A56%3C%2FreqTime%3E%0A++++%3CmerVar%3E%3C%2FmerVar%3E%0A++++%3CtranData%3EPD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48dHJhbkRhdGE%2BPHBsYXRPcmRlck5vPiNwbGF0T3JkZXJObzwvcGxhdE9yZGVyTm8%2BPG1lcmNoYW50T3JkZXJOTz4jbWVyY2hhbnRPcmRlck5PPC9tZXJjaGFudE9yZGVyTk8%2BPGVkaXRNb2RlPiNlZGl0TW9kZTwvZWRpdE1vZGU%2BPHByb2R1Y3RDb2RlPiNwcm9kdWN0Q29kZTwvcHJvZHVjdENvZGU%2BPHByb2R1Y3ROdW0%2BI3Byb2R1Y3ROdW08L3Byb2R1Y3ROdW0%2BPHRpY2tldE51bWJlcj48L3RpY2tldE51bWJlcj48L3RyYW5EYXRhPg%3D%3D%3C%2FtranData%3E%0A++++%3CsignData%3Eb270657fc5677facee5312a194bd9da4%3C%2FsignData%3E%0A%3C%2Freq%3E';
$txt2 = urldecode($txt1);
$data1= simplexml_load_string($txt2);
$reqTime = (string)$data1->reqTime;
$signData = (string)$data1->signData;
$tranData = base64_decode((string)$data1->tranData);
print_r($tranData);exit;
$check_in = md5($tranData.$AGENT_KEY);
$tranData1 = simplexml_load_string($tranData);
$platOrderNo = (string)$tranData1->platOrderNo; //爱森斯订单号
$merchantOrderNO = (string)$tranData1->merchantOrderNO; //票付通订单号
$editMode  = (int)$tranData1->editMode; //1线下取票 2按票号退订 3商品使用 16整单退订
$productCode = (string)$tranData1->productCode; //商品编码
$productNum = (int)$tranData1->productNum ; //数量 
echo $signData."<br/>".$check_in;exit;
if($signData == $check_in){
	$pft_order = $inSide->Order_Globle_Search(
									0,0,0,0,"",
									"","","","","",
									"","",$merchantOrderNO,"",0,
									"","","",1,0,
									0,1,"","","",
									"","","","","",
									"","","1","","");
	$pft_order_xml =simplexml_load_string($pft_order);
	$tid = (int)$pft_order_xml->Rec->UUtid;
	$lid = (int)$pft_order_xml->Rec->UUlid;
	$UUmemo = explode('_',(string)$pft_order_xml->Rec->UUmemo);
	$memo = $UUmemo[1];
	$UUstatus =(int)$pft_order_xml->Rec->UUstatus;
	$UUtnum =(int)$pft_order_xml->Rec->UUtnum;
	$UUsalerid =(string)$pft_order_xml->Rec->UUsalerid;
	$UUcode = (string)$pft_order_xml->Rec->UUcode;

	$select_uuid = "select uuid from uu_jq_ticket where id=".$tid." limit 1";
	$GLOBALS['le']->query($select_uuid);
	$GLOBALS['le']->fetch_assoc();
	$uuid = $GLOBALS['le']->f('uuid');

	if(($platOrderNo == $memo) && ($productCode == $uuid) && ($UUstatus==0) && ($productNum==$UUtnum) && ($editMode == 3)){
		$r = $inSide->Terminal_Check_In($UUsalerid,$UUcode,$reqTime,"");
		if(is_numeric($r)){
			$repCode = 0;
			$repMsg = Err_Word($r);
		}else{
			$r_xml = simplexml_load_string($r);
			$r_order = (string)$r_xml->Rec->UUordernum;
			if($r_order == $merchantOrderNO){
				$repCode = 1;
				$repMsg = '成功';			
			}
		}
	}
	else{
		// logfile($platOrderNo."|".$memo."|".$productCode."|".$uuid."|".$UUstatus."|".$productNum."|".$UUtnum."|".$editMode);
		$repCode = 0;
		$repMsg = '不满足验证条件，验证失败';		
	}
}else{
	$repCode = 0;
	$repMsg = '签名校验不通过';
}
if($repMsg){
	$tranData='<?xml version="1.0" encoding="UTF-8" ?><notifyData><repCode>'.$repCode.'</repCode><repMsg>'.$repMsg.'</repMsg></notifyData>';
	$request = $ass->ass_post($tranData);	
	logfile($repMsg."|".$request);
	echo $request;
}
function logfile($txt){
	$fp = fopen("/var/www/html/new/d/module/api/AiSiSen/terminal_log.txt","a");
	flock($fp, LOCK_EX) ;
	fwrite($fp,$txt."\n");
	flock($fp, LOCK_UN);
	fclose($fp); 
}
function Err_Word($r){
	$errCode = array(
		'105'=>'找不到订单',
		'121'=>'订单状态出错,订单已验证',
		'119'=>'订单状态出错,已取消或其他状态',
		'521'=>'验证间隔时间未到',
		'133'=>'游玩时间未到',
		'134'=>'游玩时间已过',
		'118'=>'终端服务器无响应',
		'1070'=>'订单未支付',
	);
	$eword=$errCode[$r];
	if (!$eword) $eword='其他错误';
	return $eword;
}
?>